﻿using PRO.DbProvider;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using PRO.Data;

namespace PRO.Data.SqlServer
{
    public partial class PublicManager : IPublicProvider
    {
        //@Tables varchar(1000), --表名如testtable 
        //@PrimaryKey varchar(100),--表的主键,必须唯一性 
        //@Sort varchar(200) = NULL,--排序字段如f_Name asc或f_name desc(注意只能有一个排序字段) 
        //@CurrentPage int = 1,--当前页 
        //@PageSize int = 10,---每页大小 
        //@Fields varchar(1000) = '*',--显示的字段列表 
        //@Filter varchar(1000) = NULL,--条件语句,不加where,如 f_id>3 
        //@Group varchar(1000) = NULL,--分组字段 
        //@TotalPage int output --返回总页数 
        public DataTable CutPage(string tablename, string keys, string sort, int pageindex, int pagesize, string fields, string filter, string group, out int TotalPage, out int counts)
        {
            DataTable dt = new DataTable();
            SqlParameter[] prams = new SqlParameter[10];

            prams[0] = new SqlParameter("@Tables", SqlDbType.NVarChar, 2000);
            prams[0].Value = tablename;

            prams[1] = new SqlParameter("@PrimaryKey", SqlDbType.NVarChar, 100);
            prams[1].Value = keys;

            prams[2] = new SqlParameter("@Sort", SqlDbType.NVarChar, 200);
            prams[2].Value = sort;

            prams[3] = new SqlParameter("@CurrentPage", SqlDbType.Int, 4);
            prams[3].Value = pageindex;

            prams[4] = new SqlParameter("@PageSize", SqlDbType.Int, 4);
            prams[4].Value = pagesize;

            prams[5] = new SqlParameter("@Fields", SqlDbType.NVarChar, 4000);
            prams[5].Value = fields;

            prams[6] = new SqlParameter("@Filter", SqlDbType.NVarChar, 4000);
            prams[6].Value = filter;

            prams[7] = new SqlParameter("@Group", SqlDbType.NVarChar, 1000);
            prams[7].Value = group;

            prams[8] = new SqlParameter("@TotalPage", SqlDbType.Int, 4);
            prams[8].Direction = ParameterDirection.Output;

            prams[9] = new SqlParameter("@ColumnsCounts", SqlDbType.Int, 4);
            prams[9].Direction = ParameterDirection.Output;

            dt = DbHelper.ExecuteDataset(CommandType.StoredProcedure, "CutPage_PRO", prams).Tables[0];
            TotalPage = Convert.ToInt32(prams[8].Value);
            counts = Convert.ToInt32(prams[9].Value);
            return dt;
        }

    }
}
